﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class EnemyButtonCreater : MonoBehaviour
{
    public string button_show_text;

    public GameObject button_enemy_prefab;

    public GameObject playermanager_gameobject;
  // Use this for initialization
  void Start()
    {
        CreatEnemyButton();
    }

    void CreatEnemyButton()
    {
        GameObject partentUI = GameObject.Find("PersonSelectTargetBtnPanel");
         GameObject enemyselectbutton =  Instantiate(   button_enemy_prefab   , partentUI.transform  );
        enemyselectbutton.transform.GetChild(0).GetComponent<Text>().text = button_show_text;
       

        enemyselectbutton.GetComponent<EnemySelectButtonFlag>().SetButtonPoint_Enemyobject(this.gameObject , this.gameObject.transform.position);

        enemyselectbutton.GetComponent<Button>().onClick.AddListener(delegate () {
            SelectTarget(   enemyselectbutton.GetComponent<EnemySelectButtonFlag>().GetEnemyPos() );
        });

    }


    void SelectTarget(  Vector3  targetPos  )
    {



        //设置当前选择对象的 攻击目标的坐标
        PlayerManager.Instance.Set_Select_Target_Pos(  targetPos  );

        //执行一个  发送攻击者状态的命名
        //发送关闭所有UI面板的 事件
        PlayerManager.Instance.CloseAll_Panel();

        //添加攻击敌人的动作
        bool isDrive = GameDataManager.Instance.CheckPersonIsDriveTank();
        //这里还要判断 角色是否驾车，，来判定需要执行什么具体策略

        if (isDrive)
        {
            PlayerManager.Instance.AddTankZhuPaoAttackEnemyAction();
        }
        else
        {
            PlayerManager.Instance.AddPersonAttackEnemyAction();
        }
      
    }


    // Update is called once per frame
    void Update()
    {
           
    }
}
